home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / JTools / IFF / double_pic < prev    next >
Encoding:
Text File  |  1992-01-28  |  1.7 KB  |  95 lines

  1. \ Simple Double Buffered display.
  2. \
  3. \ NOTE: You may want to change the filenames in DP.INIT
  4. \  to use your own files.
  5. \
  6. \ Author: Phil Burk
  7. \ Copyright 1992 Phil Burk
  8.  
  9. include? goto.error ju:goto_error
  10. include jiff:load_pic
  11.  
  12. ANEW TASK-DOUBLE_PIC
  13.  
  14. picture BACKG0
  15. picture BACKG1
  16. picture SHIP
  17.  
  18. : DP.TERM ( -- , free all pictures )
  19.     backg0 pic.free
  20.     backg1 pic.free
  21.     ship pic.free
  22.     gr.term
  23. ;
  24.  
  25. : DP.INIT  ( -- error? )
  26.     gr.init
  27. \ Load pictures from disk.  Change these to your files if desired.
  28.     " jpics:mountains.pic" backg0 $pic.load? ?goto.error
  29.     " jpics:ship.br"       ship $pic.load? ?goto.error
  30. \
  31. \ Make second background same as first
  32.     backg0 backg1 pic.duplicate? ?goto.error
  33.     backg0 backg1 pic.copy
  34. \
  35. \ Allocate backup buffers for brush
  36.     0 ship pic.alloc.backup? ?goto.error
  37.     1 ship pic.alloc.backup? ?goto.error
  38. \
  39. \ Allocate shadow for transparent blit
  40.     ship pic.alloc.shadow? ?goto.error
  41.     ship pic.cast.shadow
  42. \
  43. \ return false for ALL OK?
  44.     false
  45.     exit
  46. ERROR:
  47.     true \ return true if error
  48.     exit
  49. ;
  50.  
  51. variable CUR-BUFFER# \ 0 or 1
  52.  
  53. : DP.DRAW  { | x y curbuf -- }
  54.     100 0
  55.     DO
  56. \
  57. \ figure out which buffer is for drawing and which for display
  58.         cur-buffer# @ 1 xor 1 and dup cur-buffer# !
  59.         IF backg1
  60.         ELSE backg0
  61.         THEN
  62.         -> curbuf
  63.         curbuf pic.drawto
  64. \
  65. \ restore what was underneath previous picture
  66.         i 1 >  \ only after having done a backup
  67.         IF
  68.             cur-buffer# @ ship pic.restore.nth
  69.         THEN
  70. \
  71. \ draw ship at new position x and y position
  72.         30 i 2* + -> x
  73.         5 i + -> y
  74.         x y cur-buffer# @ ship pic.backup.nth
  75.         x y ship pic.trans.blit
  76. \
  77. \ now display picture we just drew, and wait
  78.         curbuf pic.view
  79.         2 wait.frames
  80.     LOOP
  81. ;
  82.  
  83. : DBLPIC ( -- )
  84.     dp.init 0=
  85.     IF
  86.         dp.draw
  87.     ELSE ." Error in initialization!" cr
  88.     THEN
  89.     dp.term
  90. ;
  91.  
  92. if.forgotten dp.term
  93.  
  94. cr ." Enter:   DBLPIC" cr
  95.